package kr.hkit.powerjava.chapter26;

import java.sql.Connection;
import java.util.Scanner;

import kr.hkit.powerjava.chapter26.common.ConnectionFactory;
import kr.hkit.powerjava.chapter26.common.DbUtil;
import kr.hkit.powerjava.chapter26.dto.Department;
import kr.hkit.powerjava.chapter26.dto.Employee;
import kr.hkit.powerjava.chapter26.service.AbsService;
import kr.hkit.powerjava.chapter26.service.DepartmentService;
import kr.hkit.powerjava.chapter26.service.EmployeeService;

public class TestMain {

	public static void main(String[] args) {
		/*
		 * String driver = "com.mysql.jdbc.Driver"; String url =
		 * "jdbc:mysql://localhost:3306/mysql_study"; String user = "root";
		 * String password = "1111";
		 * 
		 * DBProperies.savePropertis("dbcon.xml", driver, url, user, password);
		 * 
		 * Properties prop = DBProperies.loadPropertis("dbcon.xml");
		 * 
		 * System.out.println(prop.getProperty("DRIVER"));
		 * System.out.println(prop.getProperty("URL"));
		 * System.out.println(prop.getProperty("USER"));
		 * System.out.println(prop.getProperty("PASSWORD"));
		 * 
		 * DBProperies.prnProperties(prop); 설정 확인
		 * 
		 * Connection con = ConnectionFactory.getConnection();접속 확인
		 * System.out.println(con);
		 * 
		 * DepartmentDAO dao = new DepartmentDAO(); Department d= new
		 * Department(6, "마케팅", 8);
		 * 
		 * try { dao.insertItem(d); System.out.println("삽입성공" + d); } catch
		 * (SQLException e) { System.err.println(e.getMessage() + " : " +
		 * e.getErrorCode()); }
		 * 
		 * try { d.setDeptName("교육"); dao.updateItembyNo(d);
		 * System.out.println("수정성공" + d); } catch (SQLException e) {
		 * System.err.println(e.getMessage() + " : " + e.getErrorCode()); }
		 * 
		 * try { dao.deleteItembyNo(new Department(6));
		 * System.out.println("삭제성공" + d); } catch (SQLException e) {
		 * System.err.println(e.getMessage() + " : " + e.getErrorCode()); }
		 * 
		 * try { ArrayList<Department> list = dao.listItems(); for(Department a
		 * : list){ System.out.println(a); } } catch (SQLException e) { // TODO
		 * Auto-generated catch block e.printStackTrace(); }
		 */
		Scanner sc = new Scanner(System.in);
		Connection connection = ConnectionFactory.getConnection();
		boolean flag = true;

		while (flag) {
			System.out.print("1.부서\t2.사원\t3. 종료");

			switch (sc.nextInt()) {
			case 1:
				AbsService<Department> deptSvc = new DepartmentService(sc,
						connection);
				deptSvc.prnMenu();
				break;
			case 2:
				AbsService<Employee> empSvc = new EmployeeService(sc,
						connection);
				empSvc.prnMenu();
				break;
			default:
				flag = false;
				sc.close();
			}
		}

		DbUtil.close(connection);

	}
}
